<?php
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/user/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/qq/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/mblog/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/gonglue/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/taobao/inc.php");

/*ini_set("display_errors",true);
error_reporting(E_ALL);*/
//所有的参数
$g_cgival 	= array();
//存储中间数据 非输出数据 可以不用
$g_pro	 	= array();
//要显示的数据 输出数据
$g_show 	= array();

function check_cgi_pro()
{		
	global $g_cgival, $g_pro, $g_show, $config;
	
	cgi::both($g_cgival["p"], "p", "");
	$g_cgival["p"] = intval($g_cgival["p"]);
	
	if($g_cgival["p"] < 1) $g_cgival["p"]=1;
	
	cgi::both($g_cgival["topic_id"], "topic_id", "");
	$g_cgival["topic_id"] = intval($g_cgival["topic_id"]);
	
	cgi::both($g_cgival["ct"], "ct", "");
	
	cgi::both($g_cgival["q"], "q", "");
	$g_cgival["q"] = trim(string::un_html($g_cgival["q"]));
	
}


function get_data()
{
	global $g_cgival, $g_pro, $g_show, $config;
	$g_show["channel"] = "mblog";
	$pcount = $g_cgival["pcount"] = 20;
	$p = $g_cgival["p"];

	$topic_id = $g_cgival["topic_id"] = $config["current_site_id"];

	$g_show["topic_id"] = $topic_id;
	$g_show["q"] = $q = $g_cgival["q"];
	$g_show["ct"] = $ct = $g_cgival["ct"];
	
	if($topic_id)
	{
		$db_mblog_cron_topic_tag = new db_mblog_cron_topic_tag();
		$g_show["topic_info"]= $db_mblog_cron_topic_tag->get_mblog_cron_topic_tag_item_by_id($topic_id);
		
	}
	
	
	$db_gonglue = new db_gonglue();
	$list = $db_gonglue->get_list_order_by_time($p,$pcount,$ct,$topic_id,$q);
	
	$db_mblog_cron_topic_tag = new db_mblog_cron_topic_tag();
	foreach($list as $key => $value)
	{
		$list[$key]["content_type_name"] = $config["site_name"][$value["topic_id"]]. $config["gonglue_content_type"][$list[$key]["content_type"]];	
		$list[$key]["domain_url"] = "http://".$config["domain_url"][$value["topic_id"]];
	}
	
	
	$count = $db_gonglue->get_count($ct,$topic_id,$q);
	
	$g_show["count"] = $count;
	$g_show["list"] = $list;
	
	$Pages = new Pages($g_show["count"],$g_cgival["p"],$g_cgival["pcount"]);
	$g_show["page_bar"] = $Pages->getLinks_static("/gonglue/index_{$g_cgival["ct"]}_replacepage.html",10);
	
	
	/*$db_taobao_goods_item = new db_taobao_goods_item();
	$tao_tuijian = $db_taobao_goods_item->get_taobao_list_by_site_id(1,10);
	
	$g_show["tao_tuijian"] = $tao_tuijian;*/

	
	$db_taobao_goods_item = new db_taobao_goods_item();
	$tao_tuijian = $db_taobao_goods_item->get_taobao_list_by_site_id(1,10);
	
	$g_show["tao_tuijian"] = $tao_tuijian;
	
	
	$current_site_name = $config["current_site_name"];
	$g_show["page_keywords"]  = "{$current_site_name},{$current_site_name}攻略,{$current_site_name}视频攻略,{$current_site_name}资讯";

	if($config["site_alias"][$config["current_site_id"]])
	{
		foreach($config["site_alias"][$config["current_site_id"]] as $value)
		{
			$g_show["page_keywords"]  .= ",{$value},{$value}攻略,{$value}资讯,{$value}新闻,{$value}视频攻略";
		
		}
	}
	
	
	$g_show["page_desc"]  = "{$current_site_name}攻略_游戏美图_最有意思的游戏玩家分享平台";
	$g_show["page_title"] = "{$current_site_name}攻略_游戏美图_最有意思的游戏玩家分享平台";
	
	
	
	//右侧推荐
		$db_gonglue = new db_gonglue();
		$gonglue_list1 = $db_gonglue->get_list_order_by_time(1,6,0,$config["current_site_id"]);
		$gonglue_list2 = $db_gonglue->get_list_order_by_time(1,6,1,$config["current_site_id"]);
		foreach($gonglue_list1 as $key => $value)
		{
			if($value["topic_id"])
			{
				$gonglue_list1[$key]["topic_name"] = $config["site_name"][$value["topic_id"]];
				$gonglue_list1[$key]["domain_url"] = "http://".$config["domain_url"][$value["topic_id"]];
			}
			$gonglue_list1[$key]["title_short"] = string_utf8::substr_utf8_cn_v2($gonglue_list1[$key]["title"],36);
		}
		
		foreach($gonglue_list2 as $key => $value)
		{
			if($value["topic_id"])
			{
				$gonglue_list2[$key]["topic_name"] = $config["site_name"][$value["topic_id"]];
				$gonglue_list2[$key]["domain_url"] = "http://".$config["domain_url"][$value["topic_id"]];
			}
			$gonglue_list2[$key]["title_short"] = string_utf8::substr_utf8_cn_v2($gonglue_list2[$key]["title"],36);
		}
			
		
		$g_show["gonglue_list1"] = $gonglue_list1;
		$g_show["gonglue_list2"] = $gonglue_list2;
		
		$db_mblog_meinv_content = new db_mblog_meinv_content();
		$meinv_tuijian_list = $db_mblog_meinv_content->get_mblog_meinv_list_by_tuijian(1,9);
		foreach($meinv_tuijian_list as $key => $value)
		{
			$meinv_tuijian_list[$key]["pic_small"]  = str_replace("/bmiddle/","/thumb150/",$meinv_tuijian_list[$key]["pic"]);
		}
		
		$g_show["meinv_tuijian_list"] = $meinv_tuijian_list;
	
	
}

try {
	$g_show['error'] = 0;
	$g_show['errmsg'] = "";
	check_cgi_pro();
	get_data();
	$g_show["hide_shadow"] = true;
	
} catch (Exception $e) {
	$g_show['error'] = 1;
	$g_show['errmsg'] = $e->getMessage();
}

show_pro();


exit;

function show_pro()
{
	global $g_cgival, $g_pro, $g_show, $config;

	$smarty = p_get_smarty();	
	$smarty->assign("g_show", $g_show);
	if (isset($_GET["debug"]))
	{
		print_r($g_show);
	}
	$smarty->display("gonglue/index.html");
	
	unset($g_cgival);
	unset($g_pro);
	unset($g_show);
	unset($config);
	
}

